﻿Imports Mysoft.Map.Application.Security
Imports Mysoft.Map.Data
Imports System.Data

Partial Public Class Desk_ProjNews
    Inherits Mysoft.Map.Application.Security.AppPage

    Protected strProjName, strKpCount, strWsCount, strYrgCount, strYqyCount As String
    Protected strLdCount_Td, strLfCount_Td, strYydCount_Td, strRgzlCount_Td, strRgjeCount_Td, strQyzlCount_Td, strQyjezlCount_Td, strTfCount_Td As String
    Protected strLdCount_Yd, strLfCount_Yd, strYydCount_Yd, strRgzlCount_Yd, strRgjeCount_Yd, strQyzlCount_Yd, strQyjezlCount_Yd, strTfCount_Yd As String
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim strProjGUID, strType As String
        '初始值为0
        strProjName = ""
        strKpCount = "0"
        strWsCount = "0"
        strYrgCount = "0"
        strYqyCount = "0"
        '今日新增
        strLdCount_Td = "0"
        strLfCount_Td = "0"
        strYydCount_Td = "0"
        strRgzlCount_Td = "0"
        strRgjeCount_Td = "0"
        strQyzlCount_Td = "0"
        strQyjezlCount_Td = "0"
        '昨日新增
        strLdCount_Yd = "0"
        strLfCount_Yd = "0"
        strYydCount_Yd = "0"
        strRgzlCount_Yd = "0"
        strRgjeCount_Yd = "0"
        strQyzlCount_Yd = "0"
        strQyjezlCount_Yd = "0"
        If Not IsPostBack Then
            If Not Request.QueryString("ProjGUID") Is Nothing Then
                strProjGUID = Request.QueryString("ProjGUID")
                Bind_Data(strProjGUID)
            End If

        End If

        strProjName = Request.QueryString("projName").ToString()
    End Sub

    Private Sub Bind_Data(ByVal strProjGUID As String)
        Dim strWherePlan As String
        Dim dtTmp As New DataTable
        Dim strAlterDays As String
        Dim strSQL As String
        'Dim myPubMng As New Mysoft.Slxt.Business.PublicMng

        strWherePlan = "(2=2)"

        '房间信息状态统计
        strSQL = "Select count(1) as kscount,IsNULL(sum(case when Status='销控' then 1 else 0 end),0) as xkcount" & _
                ", IsNULL(sum(case when Status='待售' then 1 else 0 end),0) as wscount" & _
                ", IsNULL(sum(case when Status='认购' then 1 else 0 end),0) as rgcount" & _
                ", IsNULL(sum(case when Status='签约' then 1 else 0 end),0) as qycount" & _
                " From p_room where ProjGUID in ('" & strProjGUID.Replace(",", "','") & "') and (SaleRentable='出售' or SaleRentable='租售') "
        dtTmp = MyDB.GetDataTable(strSQL)
        If dtTmp.Rows.Count > 0 Then
            strKpCount = (Integer.Parse(dtTmp.Rows(0).Item("kscount")) - Integer.Parse(dtTmp.Rows(0).Item("xkcount"))).ToString
            strWsCount = dtTmp.Rows(0).Item("wscount").ToString
            strYrgCount = dtTmp.Rows(0).Item("rgcount").ToString
            strYqyCount = dtTmp.Rows(0).Item("qycount").ToString
        End If

        '机会类别统计（当天）
        strSQL = "Select IsNULL(sum(case when OppSource='来电' and (DATEDIFF(D,CreatedOn,GETDATE()) = 0) then 1 else 0 end),0) as ldcount_td" & _
        ", IsNULL(sum(case when OppSource='来访' and (DATEDIFF(D,CreatedOn,GETDATE()) = 0) then 1 else 0 end),0) as lfcount_td" & _
        ", IsNULL(sum(case when OppSource='来电' and (DATEDIFF(D,CreatedOn,GETDATE()) = 1) then 1 else 0 end),0) as ldcount_yd" & _
        ", IsNULL(sum(case when OppSource='来访' and (DATEDIFF(D,CreatedOn,GETDATE()) = 1) then 1 else 0 end),0) as lfcount_yd" & _
        " From s_Opportunity where ProjGUID in ('" & strProjGUID.Replace(",", "','") & "') "
        dtTmp = MyDB.GetDataTable(strSQL)
        If dtTmp.Rows.Count > 0 Then
            strLdCount_Td = dtTmp.Rows(0).Item("ldcount_td").ToString
            strLfCount_Td = dtTmp.Rows(0).Item("lfcount_td").ToString
            strLdCount_Yd = dtTmp.Rows(0).Item("ldcount_yd").ToString
            strLfCount_Yd = dtTmp.Rows(0).Item("lfcount_yd").ToString
        End If

        '预约单统计（当天、昨天）
        strSQL = "Select IsNULL(sum(case when Status='排号' and (DATEDIFF(D,BgnDate,GETDATE()) = 0)  then 1 else 0 end),0) as yydCount_td" & _
                ", IsNULL(sum(case when Status='排号' and (DATEDIFF(D,BgnDate,GETDATE()) = 1)  then 1 else 0 end),0) as rgjecount_yd" & _
                " From s_Booking where ProjGUID in ('" & strProjGUID.Replace(",", "','") & "')  "
        dtTmp = MyDB.GetDataTable(strSQL)
        If dtTmp.Rows.Count > 0 Then
            strYydCount_Td = dtTmp.Rows(0).Item("yydCount_td").ToString
            strYydCount_Yd = dtTmp.Rows(0).Item("rgjecount_yd").ToString
        End If


        '定单状态统计（当天、昨天）
        strSQL = "Select IsNULL(sum(case when (DATEDIFF(D,QsDate,GETDATE()) = 0)  then 1 else 0 end),0) as rgzlcount_td" & _
                ", IsNULL(sum(case when (DATEDIFF(D,QsDate,GETDATE()) = 1) then 1 else 0 end),0) as rgzlcount_yd" & _
                ", IsNULL(sum(case when (DATEDIFF(D,QsDate,GETDATE()) = 0) then RmbCjTotal else 0 end),0) as rgjecount_td" & _
                ", IsNULL(sum(case when (DATEDIFF(D,QsDate,GETDATE()) = 1) then RmbCjTotal else 0 end),0) as rgjecount_yd" & _
                " From s_order where ProjGUID in ('" & strProjGUID.Replace(",", "','") & "') and OrderType='认购' and Status='激活' "
        dtTmp = MyDB.GetDataTable(strSQL)
        If dtTmp.Rows.Count > 0 Then
            strRgzlCount_Td = dtTmp.Rows(0).Item("rgzlcount_td").ToString
            strRgjeCount_Td = Format(dtTmp.Rows(0).Item("rgjecount_td"), "#,##0.00")
            strRgzlCount_Yd = dtTmp.Rows(0).Item("rgzlcount_yd").ToString
            strRgjeCount_Yd = Format(dtTmp.Rows(0).Item("rgjecount_yd"), "#,##0.00")
        End If

        '合同状态统计（当天、昨天）
        strSQL = "Select IsNULL(sum(case when Status='激活' and (DATEDIFF(D,QsDate,GETDATE()) = 0) then 1 else 0 end),0) as qyzlcount_td" & _
                ", IsNULL(sum(case when Status='激活' and (DATEDIFF(D,QsDate,GETDATE()) = 1) then 1 else 0 end),0) as qyzlcount_yd" & _
                ", IsNULL(sum(case when Status='激活' and (DATEDIFF(D,QsDate,GETDATE()) = 0) then RmbHtTotal else 0 end),0) as qyjezlcount_td" & _
                ", IsNULL(sum(case when Status='激活' and (DATEDIFF(D,QsDate,GETDATE()) = 1) then RmbHtTotal else 0 end),0) as qyjezlcount_yd" & _
                ", IsNULL(sum(case when CloseReason  ='退房' and (DATEDIFF(D,CloseDate,GETDATE()) = 0)  then 1 else 0 end),0) as tfcount_td" & _
                ", IsNULL(sum(case when CloseReason  ='退房' and (DATEDIFF(D,CloseDate,GETDATE()) = 1) then 1 else 0 end),0) as tfcount_yd" & _
                " From s_Contract where ProjGUID in ('" & strProjGUID.Replace(",", "','") & "') "
        dtTmp = MyDB.GetDataTable(strSQL)
        If dtTmp.Rows.Count > 0 Then
            strQyzlCount_Td = dtTmp.Rows(0).Item("qyzlcount_td").ToString
            strQyjezlCount_Td = Format(dtTmp.Rows(0).Item("qyjezlcount_td"), "#,##0.00")
            strTfCount_Td = dtTmp.Rows(0).Item("tfcount_td").ToString

            strQyzlCount_Yd = dtTmp.Rows(0).Item("qyzlcount_yd").ToString
            strQyjezlCount_Yd = Format(dtTmp.Rows(0).Item("qyjezlcount_yd"), "#,##0.00")
            strTfCount_Yd = dtTmp.Rows(0).Item("tfcount_yd").ToString
        End If

    End Sub

End Class